<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>宠物邻里互助平台</title>
    <style>
        :root {
            --primary-color: #FFB300;
            --primary-dark: #FF8F00;
            --primary-light: #FFECB3;
            --primary-bg: #FFFDE7;
            --text-dark: #5D4037;
            --text-medium: #795548;
            --text-light: #BCAAA4;
            --white: #FFFFFF;
            --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
            --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
            --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
            --radius-sm: 8px;
            --radius-md: 12px;
            --radius-lg: 16px;
            --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Helvetica Neue', Arial, 'Microsoft YaHei', sans-serif;
        }

        body {
            background-color: var(--primary-bg);
            color: var(--text-dark);
            line-height: 1.6;
        }

        .container {
            max-width: 1200px;
            margin: 40px auto;
            padding: 30px;
            background-color: var(--white);
            border-radius: var(--radius-lg);
            box-shadow: var(--shadow-lg);
            position: relative;
            overflow: hidden;
        }

        .container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 8px;
            background: linear-gradient(90deg, var(--primary-color), var(--primary-dark));
        }

        h1 {
            color: var(--primary-dark);
            margin: 20px 0 30px;
            text-align: center;
            font-weight: 700;
            font-size: 2.5rem;
            position: relative;
            display: inline-block;
            width: 100%;
        }

        h1::after {
            content: '';
            display: block;
            width: 80px;
            height: 4px;
            background: var(--primary-color);
            margin: 15px auto 0;
            border-radius: 2px;
        }

        .search-bar {
            display: flex;
            margin-bottom: 30px;
            gap: 15px;
            max-width: 800px;
            margin-left: auto;
            margin-right: auto;
        }

        .search-bar input {
            flex: 1;
            padding: 15px 25px;
            border: 2px solid var(--primary-light);
            border-radius: 50px;
            font-size: 16px;
            transition: var(--transition);
            box-shadow: var(--shadow-sm);
        }

        .search-bar input:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(255, 179, 0, 0.2);
        }

        .search-bar button {
            background-color: var(--primary-color);
            color: var(--white);
            border: none;
            border-radius: 50px;
            padding: 0 30px;
            cursor: pointer;
            transition: var(--transition);
            font-weight: 600;
            font-size: 16px;
            box-shadow: var(--shadow-sm);
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .search-bar button:hover {
            background-color: var(--primary-dark);
            transform: translateY(-2px);
            box-shadow: var(--shadow-md);
        }

        .become-host-btn {
            background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
            color: var(--white) !important;
            padding: 12px 25px;
            border-radius: 50px;
            text-decoration: none;
            font-weight: 600;
            display: inline-flex;
            align-items: center;
            gap: 10px;
            transition: var(--transition);
            box-shadow: var(--shadow-sm);
            margin-bottom: 20px;
            border: none;
            cursor: pointer;
        }

        .become-host-btn:hover {
            transform: translateY(-3px);
            box-shadow: var(--shadow-md);
            background: linear-gradient(135deg, var(--primary-dark), #E65100);
        }

        .foster-families {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
            gap: 30px;
            margin-top: 40px;
        }

        .family-card {
            background-color: var(--white);
            border-radius: var(--radius-md);
            padding: 0;
            transition: var(--transition);
            border: 1px solid var(--primary-light);
            box-shadow: var(--shadow-sm);
            display: flex;
            flex-direction: column;
            overflow: hidden;
            position: relative;
        }

        .family-card:hover {
            transform: translateY(-5px);
            box-shadow: var(--shadow-lg);
            border-color: var(--primary-color);
        }

        .family-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 5px;
            background: linear-gradient(90deg, var(--primary-color), var(--primary-dark));
        }

        .family-header {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
            padding: 20px 20px 0;
        }

        .family-avatar {
            width: 70px;
            height: 70px;
            border-radius: 50%;
            background-color: var(--white);
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 15px;
            overflow: hidden;
            border: 3px solid var(--primary-light);
            transition: var(--transition);
        }

        .family-card:hover .family-avatar {
            border-color: var(--primary-color);
        }

        .family-avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .family-info h3 {
            margin: 0;
            color: var(--text-dark);
            font-size: 20px;
            font-weight: 700;
        }

        .family-info p {
            margin: 8px 0 0;
            color: var(--text-medium);
            font-size: 14px;
            display: flex;
            align-items: center;
        }

        .family-info p i {
            margin-right: 8px;
            color: var(--primary-dark);
            font-size: 16px;
        }

        .family-rating {
            color: var(--primary-dark);
            margin-top: 5px;
            font-weight: 600;
        }

        .family-images {
            height: 180px;
            display: flex;
            overflow-x: auto;
            scroll-snap-type: x mandatory;
            margin: 15px 0;
            padding: 0;
            position: relative;
        }

        .family-images::-webkit-scrollbar {
            height: 6px;
        }

        .family-images::-webkit-scrollbar-thumb {
            background-color: var(--primary-color);
            border-radius: 3px;
        }

        .family-images img {
            scroll-snap-align: start;
            min-width: 100%;
            height: 100%;
            object-fit: cover;
            margin-right: 0;
            border: none;
        }

        .family-details {
            margin: 0;
            color: var(--text-medium);
            line-height: 1.7;
            padding: 0 20px 15px;
            font-size: 15px;
        }

        .family-tags {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin: 10px 20px;
        }

        .tag {
            background-color: var(--primary-light);
            padding: 6px 14px;
            border-radius: 20px;
            font-size: 12px;
            color: var(--text-dark);
            font-weight: 500;
        }

        .family-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: auto;
            padding: 15px 20px;
            border-top: 1px dashed var(--primary-light);
            background-color: rgba(255, 236, 179, 0.2);
        }

        .price {
            font-weight: bold;
            color: var(--primary-dark);
            font-size: 20px;
            display: flex;
            align-items: center;
        }

        .price::before {
            content: '¥';
            font-size: 16px;
            margin-right: 3px;
        }

        .book-btn {
            background: linear-gradient(to right, var(--primary-color), var(--primary-dark));
            color: var(--white);
            border: none;
            border-radius: 20px;
            padding: 10px 25px;
            cursor: pointer;
            transition: var(--transition);
            font-weight: 600;
            box-shadow: var(--shadow-sm);
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .book-btn:hover {
            background: linear-gradient(to right, var(--primary-dark), #E65100);
            transform: translateY(-2px);
            box-shadow: var(--shadow-md);
        }

        /* 筛选区域 */
        .filter-area {
            background-color: var(--white);
            border-radius: var(--radius-md);
            padding: 20px;
            margin-bottom: 30px;
            box-shadow: var(--shadow-sm);
            border: 1px solid var(--primary-light);
        }

        .filter-title {
            font-size: 18px;
            font-weight: 700;
            color: var(--text-dark);
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .filter-title i {
            color: var(--primary-dark);
        }

        .filter-group {
            margin-bottom: 25px;
        }

        .filter-group h4 {
            font-size: 16px;
            color: var(--text-dark);
            margin-bottom: 15px;
            padding-bottom: 8px;
            border-bottom: 2px solid var(--primary-light);
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .filter-group h4 i {
            color: var(--primary-dark);
            font-size: 14px;
        }

        .filter-options {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
        }

        .filter-option {
            display: flex;
            align-items: center;
            cursor: pointer;
        }

        .filter-option input {
            appearance: none;
            width: 18px;
            height: 18px;
            border: 2px solid var(--primary-light);
            border-radius: 4px;
            margin-right: 8px;
            position: relative;
            cursor: pointer;
            transition: var(--transition);
        }

        .filter-option input:checked {
            background-color: var(--primary-color);
            border-color: var(--primary-color);
        }

        .filter-option input:checked::after {
            content: '✓';
            position: absolute;
            color: white;
            font-size: 12px;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }

        .filter-option label {
            cursor: pointer;
            user-select: none;
        }

        .submit-btn {
            background: linear-gradient(to right, var(--primary-color), var(--primary-dark));
            color: white;
            border: none;
            border-radius: 50px;
            padding: 12px 30px;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
            width: 100%;
            box-shadow: var(--shadow-sm);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }

        .submit-btn:hover {
            background: linear-gradient(to right, var(--primary-dark), #E65100);
            transform: translateY(-2px);
            box-shadow: var(--shadow-md);
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .container {
                margin: 20px auto;
                padding: 20px 15px;
            }

            h1 {
                font-size: 2rem;
            }

            .search-bar {
                flex-direction: column;
            }

            .search-bar button {
                padding: 15px;
                justify-content: center;
            }

            .foster-families {
                grid-template-columns: 1fr;
            }

            .filter-options {
                flex-direction: column;
                gap: 10px;
            }
        }

        /* 动画效果 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .family-card {
            animation: fadeIn 0.5s ease forwards;
            opacity: 0;
        }

        .family-card:nth-child(1) { animation-delay: 0.1s; }
        .family-card:nth-child(2) { animation-delay: 0.2s; }
        .family-card:nth-child(3) { animation-delay: 0.3s; }
        .family-card:nth-child(4) { animation-delay: 0.4s; }
        .family-card:nth-child(5) { animation-delay: 0.5s; }
        .family-card:nth-child(6) { animation-delay: 0.6s; }
    </style>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
</head>
<body>

<jsp:include page="head.jsp"/>
<div class="container">
    <h1><i class="fas fa-paw"></i> 可寄养家庭</h1>
    <div style="text-align: center; margin-bottom: 20px;">
        <a href="${pageContext.request.contextPath}/Hosts/publish" class="become-host-btn">
            <i class="fas fa-home"></i> 成为寄养家庭
        </a>
    </div>

    <form id="searchForm" action="${pageContext.request.contextPath}/Hosts/search" method="get">
        <div class="search-bar">
            <input type="text" name="family_name" placeholder="搜索寄养家庭..." value="${param.family_name}">
            <button type="submit"><i class="fas fa-search"></i> 搜索</button>
        </div>

        <div class="filter-area">
            <div class="filter-title"><i class="fas fa-filter"></i> 筛选条件</div>

            <div class="filter-group">
                <h4><i class="fas fa-tags"></i> 价格范围</h4>
                <div class="filter-options">
                    <div class="filter-option">
                        <input type="radio" id="price-all" name="priceRange" value="all" ${param.priceRange == 'all' || empty param.priceRange ? 'checked' : ''}>
                        <label for="price-all">全部</label>
                    </div>
                    <div class="filter-option">
                        <input type="radio" id="price-under50" name="priceRange" value="under50" ${param.priceRange == 'under50' ? 'checked' : ''}>
                        <label for="price-under50">50元/天以下</label>
                    </div>
                    <div class="filter-option">
                        <input type="radio" id="price-50-100" name="priceRange" value="50-100" ${param.priceRange == '50-100' ? 'checked' : ''}>
                        <label for="price-50-100">50-100元/天</label>
                    </div>
                    <div class="filter-option">
                        <input type="radio" id="price-over100" name="priceRange" value="over100" ${param.priceRange == 'over100' ? 'checked' : ''}>
                        <label for="price-over100">100元以上/天</label>
                    </div>
                </div>
            </div>

            <button type="submit" class="submit-btn"><i class="fas fa-check"></i> 应用筛选</button>
        </div>
    </form>

    <!-- 寄养家庭列表 -->
    <div class="family-list">
        <div class="foster-families">
            <c:forEach items="${hostList}" var="family">
                <div class="family-card">
                    <div class="family-header">
                        <div class="family-avatar">
                            <img src="${family.user.icon}" alt="${family.family_name}">
                        </div>
                        <div class="family-info">
                            <h3>${family.family_name}</h3>
                            <p><i class="fas fa-map-marker-alt"></i> ${family.location}</p>
                            <div class="family-rating">
                                <i class="fas fa-star"></i> 4.8
                            </div>
                        </div>
                    </div>

                    <div class="family-images">
                        <c:forEach items="${family.env}" var="image">
                            <img src="${family.env}" alt="寄养环境">
                        </c:forEach>
                    </div>

                    <div class="family-details">
                            ${family.description}
                    </div>

                    <div class="family-tags">
                        <span class="tag"><i class="fas fa-dog"></i> 接受狗狗</span>
                        <span class="tag"><i class="fas fa-home"></i> 家庭寄养</span>
                        <span class="tag"><i class="fas fa-clock"></i> 长期可接</span>
                    </div>

                    <div class="family-footer">
                        <div class="price">${family.price}元/天</div>
                        <button onclick="bookFamily(${family.family_id}, '${family.service_types}')" class="book-btn">
                            <i class="fas fa-calendar-check"></i> 立即预约
                        </button>
                    </div>
                </div>
            </c:forEach>
        </div>
    </div>
</div>

<script>
    // 预约寄养功能
    function bookFamily(familyId, serviceType) {
        // 添加跳转路径，包含family_id和service_type两个参数
        window.location.href = '${pageContext.request.contextPath}/order/create?family_id=' + familyId + '&service_type=' + encodeURIComponent(serviceType);
    }

    // 搜索功能
    document.querySelector('.search-bar button').addEventListener('click', function(e) {
        e.preventDefault();
        document.getElementById('searchForm').submit();
    });

    // 筛选功能
    document.querySelectorAll('.filter-option input').forEach(input => {
        input.addEventListener('change', function() {
            console.log('筛选条件已变更');
        });
    });

    // 卡片悬停效果增强
    document.querySelectorAll('.family-card').forEach(card => {
        card.addEventListener('mouseenter', function() {
            this.style.transform = 'translateY(-8px)';
            this.style.boxShadow = '0 15px 30px rgba(255, 179, 0, 0.2)';
        });

        card.addEventListener('mouseleave', function() {
            this.style.transform = 'translateY(-5px)';
            this.style.boxShadow = '0 10px 25px rgba(0,0,0,0.1)';
        });
    });
</script>
</body>
</html>